<template>
  <div class="wrapper">
    <div class="title">商品信息</div>
    <div class="product-container">
      <div class="border">
        <div class="name">id：</div>
        <div class="content">{{ info.id }}</div>
      </div>
      <div class="border">
        <div class="name">订单编号：</div>
        <div class="content">{{ info.order_no }}</div>
      </div>
      <div class="border">
        <div class="name">商品：</div>
        <div class="content">{{ info.package_name }}</div>
      </div>
      <div class="border">
        <div class="name">商品图片：</div>
        <img :src="info.package_list_pic" preview="product" preview-text="商品图片" alt="" class="image">
      </div>
      <div class="border">
        <div class="name">创建时间：</div>
        <div class="content">{{ info.create_at }}</div>
      </div>
      <div class="border">
        <div class="name">有用的评论数：</div>
        <div class="content">{{ info.useful_quantity }}</div>
      </div>
    </div>
    <div class="title">用户信息</div>
    <div class="user-container">
      <div class="border">
        <div class="name">用户名：</div>
        <div class="content">{{ info.username }}</div>
      </div>
      <div class="border">
        <div class="name">用户头像：</div>
        <img :src="info.headimgurl" preview="headurl" preview-text="用户头像" alt="" class="image">
      </div>
      <div class="border">
        <div class="name">评论内容：</div>
        <div class="content">{{ info.content }}</div>
      </div>
      <div class="border">
        <div class="name">评论图片：</div>
        <img v-for="(item, index) of info.imgs" :key="index" :src="item" :preview="`${index}-commit`" preview-text="评论图片" alt="" class="image">
      </div>
      <div class="border">
        <div class="name">评分：</div>
        <el-rate v-model="info.score" score-template="{value}" disabled show-score text-color="#ff9900" />
      </div>
    </div>
    <div class="title">管理员回复信息</div>
    <div class="administrator-container">
      <div class="border">
        <div class="name">管理员回复时间：</div>
        <div class="content">{{ info.reply_at }}</div>
      </div>
      <!-- <div class="border">
        <div class="name">状态禁用：</div>
        <el-switch v-model="status" active-color="#13ce66" inactive-color="#ff4949" @change="handleStatus" />
      </div> -->
      <div class="border">
        <div class="name">管理员回复：</div>
        <textarea v-model="content" placeholder="请输入回复内容" maxlength="500" />
      </div>
    </div>
    <div class="reply">
      <el-row>
        <el-button type="primary" @click="handleReply">回复</el-button>
      </el-row>
    </div>
  </div>
</template>
<script>
import { reply, display } from '@/api/evaluate'
import { parseTime } from '@/utils'
export default {
  name: 'Detail',
  data() {
    return {
      info: {},
      content: '',
      status: true
    }
  },
  created() {
    this.initDetail()
  },
  methods: {
    initDetail() {
      // const { comment_id } = this.$route.query
      const res = this.$route.query
      // // console.log(res)
      // const res = await detail({ comment_id })
      // console.log(res)
      this.info = res
      this.info.reply_at = parseTime(this.info.reply_at)
      this.content = this.info.reply_content
      this.status = Number(this.info.is_show) === 1
      this.$previewRefresh()
    },
    handleReply() {
      const { content } = this
      if (content.trim() === '') {
        this.$message.warning({
          message: '回复内容不能为空',
          duration: 1000
        })
        return
      }
      this.replyContent(content)
    },
    replyContent(content) {
      const { comment_id } = this.$route.query
      reply({ reply_content: content, comment_id })
        .then((res) => {
          this.$message.success({
            message: '回复成功',
            duration: 1000
          })
        })
    },
    // 切换显示状态
    handleStatus(status) {
      const is_show = status ? 1 : -1
      const { comment_id } = this.$route.query
      display({ is_show, comment_id })
        .then((res) => {
          this.$message.success({
            message: '设置成功',
            duration: 1000
          })
        })
    }
  }
}
</script>

<style lang="scss" scoped>
.wrapper {
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 0;
  right: 0;
  z-index: 10;
  background-color: #fff;
  overflow-y: scroll;
  .title{
    font-size: 20px;
    line-height: 50px;
  }
  .product-container, .user-container, .administrator-container {
    width: 100%;
    border-top: 1px solid #ebeef5;
    box-sizing: border-box;
    margin-bottom: 20px;
    .border {
      padding: 10px 0;
      border: 1px solid #ebeef5;
      border-top: none;
      width: 100%;
      display: flex;
      align-items: center;
      min-height: 50px;
      box-sizing: border-box;
      .name {
        margin-left: 20px;
        margin-right: 15px;
        min-width: 100px;
      }
      .content {
        line-height: 30px;
      }
      .image-wrap {
        display: flex;
      }
      .image{
        width: 80px;
        height: 80px;
        margin-right: 20px;
        cursor: pointer;
      }
    }
  }
  textarea{
    width: 50%;
    height: 300px;
    padding: 10px;
    box-sizing: border-box;
    font-size: 14px;
    color: #050505;
    line-height: 28px;
    border: 1px solid #ebeef5;
    margin-bottom: 10px;
    resize: none;
    outline: none;
  }
  button {
    width: 200px;
  }
}
</style>
